<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>属性修改</title>
</head>
<body>
    <button id="p1">p1</button>
    <button id="p2">p2</button><br>
    <img src="../images/p1.png" alt="p1" title="p1">
    <script>
        var p1=document.getElementById('p1');
        var p2=document.getElementById('p2');
        var img=document.querySelector('img');
        p2.onclick=function(){
            img.src="../images/p2.jpg";
            img.title="p2";
        }
        p1.onclick=function(){
            img.src="../images/p1.png"
            img.title="p1";
        }
    </script>
</body>
</html>